<template>
<div>
       <hunk-head name="签名"></hunk-head>
   <div class="signbox" >
        <div class="signArea">
            <canvas class="canvas" id="canvas" canvas-id="canvas" style="width: 100%;height: 100%;"  disable-scroll="true" bindtouchstart="uploadScaleStart" @touchmove="uploadScaleMove"
        @touchend="uploadScaleEnd" canvasId="handWriting">
               
        </canvas>
         <div class="signTips" v-if="firstTouch">
                    签名时，保证手机横屏！
                </div>
        </div>
        <div class="btnbox">
            <div class="btn btn1" @click="predivCanvasImg">
                <span @click="">
                    确定
                </span>
            </div>
            <div class="btn btn2" @click="retDraw">
                <span >
                    清除
                </span>
            </div>
        </div>
    </div>
</div>
     
</template>
<script>
import Head from '@componentsMine/head'
import SignOnline from '../../lib/signOnline'
import{tEContractUpload} from '@/apis/contract'
export default{
    components: {
        'hunk-head': Head
    },
    computed: {
        // 获取tabBar的数据
        userInfo(){
            return this.$store.state.baseStore.userInfo
        },
    },
    onLoad(e){
        console.log(e)
        this.eid = e.eid
        this.so = new SignOnline(this.eventListener)
        console.log(this.so)
        this.so.init()
    },
    data(){
        return {
            firstTouch:true,
            so:{},
            eid:''
        }
    },
    methods:{
         eventListener(){
             console.log(11212)
            this.firstTouch = !this.firstTouch
        },
        uploadScaleStart(e){
            console.log(this.so)
            this.so.uploadScaleStart(e)
        },
        uploadScaleMove(e){
            this.so.uploadScaleMove(e)
        },
        uploadScaleEnd(e){
            this.so.uploadScaleEnd(e)
        },
        retDraw(){
            this.so.retDraw()
        },
        predivCanvasImg(){
            this.so.previewCanvasImg().then(e=>{
                tEContractUpload({
                    "codeBase64": e,
                    "ewid": this.eid,
                    "userid": this.userInfo.userid
                }).then(el=>{
                    if(el.code==200){
                        uni.showToast({
                            title:'签名成功',
                            icon: 'none'
                        })
                        setTimeout(() => {
                             uni.redirectTo({
                            url: '/pages/index/index'
                            })
                        }, 1000);
                       
                    }else{
                        uni.showToast({
                            title: el.msg,
                            icon: 'none'
                        })
                        setTimeout(() => {
                            uni.redirectTo({
                            url: '/pages/index/index'
                            })
                        }, 1000);
                       
                    }
                })
            })
        }
    }
}
</script>

<style lang="scss" scoped>
.hosting{
  width: 100vw;
  box-sizing: border-box;
  height: 100vh;
  background: #F9F9F9;
  display: flex;
  flex-direction: column;
}


.signbox{
    // padding: 48px 0 0 48px;
    box-sizing: border-box;
    position: relative;
    display: flex;
}
.signArea{
    /* height: 1286rpx; */
    width: calc(100vw - 62px);
    background: rgba(62, 140, 255, 0.06);
    border-radius: 4px;
    border: 1px solid rgba(62, 140, 255, 0.32);
}
.btn{
    height: calc(43vh);
    width: 45px;
    border-radius: 4px;
    font-size: 17px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    line-height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    margin-left: 13px;
}
.btn span{
    // margin-left: -22.5px;
    transform: rotate(-90deg);
}
.btn1{
    background: #3E8CFF;
    color: #FFFFFF;
   margin-bottom: 13px;
}
.btn.btn2{

    color: #3E8CFF;
    border: 1px solid #3E8CFF;
    background: #FFFFFF;
}
.canvas{
    position: relative;

}
.signTips{
    // height: 100%;
    transform: rotate(-90deg);
    position: absolute;
    top:calc(50% - 50px);
    font-size:18px;
    left:-60px;
    color:rgb(239, 29, 29);
    // justify-content:flex-start;
    // align-items: center;
    // display: flex;
}
.sginImg{
    width: 19px;
    height: 22px;
}
</style>